/*    */ package com.asiainfo.dacp.catalog.controller;
/*    */ 
/*    */ import com.asiainfo.dacp.crypto.cipher.DesCipher;
/*    */ import com.asiainfo.dacp.stat.olapcheck.DataSource;
/*    */ import java.io.PrintStream;
/*    */ import java.sql.Connection;
/*    */ import java.sql.DriverManager;
/*    */ import java.sql.SQLException;
/*    */ import java.util.HashMap;
/*    */ import java.util.Map;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import org.slf4j.Logger;
/*    */ import org.slf4j.LoggerFactory;
/*    */ import org.springframework.stereotype.Controller;
/*    */ import org.springframework.web.bind.annotation.RequestMapping;
/*    */ import org.springframework.web.bind.annotation.ResponseBody;
/*    */ 
/*    */ 
/*    */ @Controller
/*    */ public class DBTestController
/*    */ {
/* 23 */   private static Connection conn = null;
/* 24 */   private static Logger log = LoggerFactory.getLogger(DBTestController.class);
/*    */   
/*    */   @RequestMapping({"/conntest"})
/*    */   @ResponseBody
/* 28 */   public Object connTest(HttpServletRequest request, HttpServletResponse response) throws SQLException { String message = "";
/* 29 */     String driver = request.getParameter("driver");
/* 30 */     String url = request.getParameter("url");
/* 31 */     String username = request.getParameter("username");
/* 32 */     String password = request.getParameter("password");
/* 33 */     String desPassword = DesCipher.decrypt(password);
/* 34 */     DataSource ds = new DataSource(driver, url, username, desPassword);
/* 35 */     log.info("数据库URL：{},用户名：{}，密码：{}", new Object[] { url, username, password });
/*    */     try
/*    */     {
/* 38 */       Class.forName(ds.getDriver());
/* 39 */       conn = DriverManager.getConnection(ds
/* 40 */         .getUrl(), ds.getUsername(), ds.getPassword());
/* 41 */       message = "连接测试成功!";
/*    */     } catch (ClassNotFoundException e) {
/* 43 */       conn = null;
/* 44 */       message = "驱动类无法找到!";
/* 45 */       e.printStackTrace();
/*    */     } catch (SQLException e) {
/* 47 */       conn = null;
/* 48 */       if ((driver.toLowerCase().contains("mysql")) && ("28000".equalsIgnoreCase(e.getSQLState()))) {
/* 49 */         message = "用户名或者密码错误！";
/*    */       } else {
/* 51 */         message = "数据库访问异常!";
/*    */       }
/* 53 */       e.printStackTrace();
/*    */     }
/*    */     
/* 56 */     Map map = new HashMap();
/* 57 */     map.put("message", message);
/* 58 */     return map;
/*    */   }
/*    */   
/*    */   public static Connection getConn(DataSource ds) {
/*    */     try {
/* 63 */       Class.forName(ds.getDriver());
/* 64 */       conn = DriverManager.getConnection(ds
/* 65 */         .getUrl(), ds.getUsername(), ds.getPassword());
/*    */       
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/* 75 */       return conn;
/*    */     }
/*    */     catch (ClassNotFoundException e)
/*    */     {
/* 66 */       e = 
/*    */       
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/* 75 */         e;conn = null;e.printStackTrace();System.out.println("驱动类无法找到!");return conn;
/*    */     }
/*    */     catch (SQLException e)
/*    */     {
/* 70 */       e = 
/*    */       
/*    */ 
/*    */ 
/*    */ 
/* 75 */         e;conn = null;e.printStackTrace();System.out.println("数据库访问异常!");return conn; } finally {} return conn;
/*    */   }
/*    */ }


/* Location:              C:\Users\my\.m2\repository\com\asiainfo\dacp\dacp-dataos\1.0.0\dacp-dataos-1.0.0.jar!\com\asiainfo\dacp\catalog\controller\DBTestController.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */